package com.liveneo.adapter.mobile.service.impl;

import org.springframework.stereotype.Service;
import com.liveneo.adapter.base.support.LogUtils;
import com.liveneo.adapter.mobile.model.RequestHead;
import com.liveneo.adapter.mobile.model.request.ChangeTaskStatusRequest;
import com.liveneo.adapter.mobile.model.response.ChangeTaskStatusResponse;
import com.liveneo.adapter.mobile.service.MobsurveyCoreService;
import com.liveneo.adapter.mobile.util.HttpRequestUtil;
import com.liveneo.adapter.mobile.util.SysConst;
import com.liveneo.adapter.mobile.util.XMLProcessor;
import com.liveneo.system.base.utils.MD5;

/**
 * 郎泰核心服务接口
 * @author rex
 *
 */
@Service
public class MobsurveyCoreServiceImpl implements MobsurveyCoreService {
    @Override
    public ChangeTaskStatusResponse changeTaskStatus(ChangeTaskStatusRequest changeTaskStatusRequest) {
        try {
            RequestHead head = new RequestHead();
            head.setServiceCode("VideoSurveyService");
            head.setRequestID("P17");
            head.setUserCode(String.valueOf(System.currentTimeMillis()));
            String signMd5Str = MD5.GetMD5Code(head.getServiceCode() + head.getRequestID() + head.getUserCode());
            head.setUsrSignature(signMd5Str);
            changeTaskStatusRequest.setRequestHead(head);
            String url = SysConst.getProperty("MOBSURVEY_CORE_SERVICE") + "/http/changeTaskStatus.json";
            String param = XMLProcessor.beanToJson(changeTaskStatusRequest);
            LogUtils.info("-------查勘状态变更同步到调度开始---------请求参数：" + param);
            // 调度服务好了，放开
            // String dispatchFlag = SysConst.getProperty("IS_SYSN_DISPATCH");
            ChangeTaskStatusResponse taskStatusResponse = new ChangeTaskStatusResponse();
            // if(StringUtils.equals(dispatchFlag, "1")){
            taskStatusResponse = HttpRequestUtil.postXMLProcessorJson(url, param, ChangeTaskStatusResponse.class);
            // }else{
            // //不调用调度系统
            // ResponseHead responseHead=new ResponseHead();
            // responseHead.setResultCode("000");
            // taskStatusResponse.setResponseHead(responseHead);
            // }
            LogUtils.info("-------查勘状态变更同步到调度结束---------");
            return taskStatusResponse;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    // @Override
    // public __GetZoneResult_ getMobileAttr(String mobile) {
    // try {
    // if (StringUtils.isEmpty(mobile)) {
    // return null;
    // }
    // LogUtil.printConsoleLog("查询号码归属地，请求参数：" + mobile);
    // String url = SysConst.getProperty("MOBILE_ATTRIBUT") + mobile;
    // HttpPost httpPost = new HttpPost(url);
    // // StringEntity entity = new StringEntity("", Consts.UTF_8);
    // // entity.setContentType(ContentType.APPLICATION_JSON.toString());
    // // /httpPost.setEntity(entity);
    // CloseableHttpClient client = HttpClients.createDefault();
    // try {
    // // 发送结果
    // HttpResponse response = client.execute(httpPost);
    // // 响应实体
    // HttpEntity rsentity = response.getEntity();
    // if (rsentity != null) {
    // // 获取返回结果
    // String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
    // LogUtil.printConsoleLog("查询号码归属地，返回参数：" + result);
    // String __GetZoneResult_AttrStr = result.replaceAll("=", ":");
    // __GetZoneResult_ getZoneResult = XMLProcessor.jsonToBean("{" + __GetZoneResult_AttrStr + "}",
    // __GetZoneResult_.class);
    // return getZoneResult;
    // }
    // } catch (Exception e) {
    // e.printStackTrace();
    // LogUtil.printConsoleLog("查询号码归属地异常：" + e.getMessage());
    // } finally {
    // if (client != null) {
    // try {
    // client.close();
    // } catch (IOException e) {
    // }
    // }
    // }
    // } catch (UserException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // return null;
    // }
}
